package com.happyrecyclingstation.controller.admin;

import com.happyrecyclingstation.dto.AdminUserQueryDto;
import com.happyrecyclingstation.service.UserService;
import com.happyrecyclingstation.utils.Result;
import com.happyrecyclingstation.vo.AdminUserVO;
import com.happyrecyclingstation.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员
 */
@Slf4j
@RequestMapping("/admin/users")
@RestController("adminUserController")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 管理查询用户列表
     * @param queryParam
     * @return
     */
    @GetMapping
    public Result getUser(AdminUserQueryDto queryParam){
        log.info("管理员获取用户列表:{}", queryParam);
        PageResult<AdminUserVO> pageResult = userService.getUser(queryParam);
        return Result.success(pageResult);
    }

    /**
     * 启用或禁用用户
     * @param status
     * @param id
     * @return
     */
    @PutMapping("/{status}")
    public Result startOrStopUser(@PathVariable("status") Short status,  Integer id){
        log.info("管理员启用或禁用用户:{},{}", status, id);
        userService.startOrStopUser(status, id);
        return Result.success();
    }
}
